<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @SWG\Definition(
 *      definition="House",
 *      required={"title", "content", "country", "state_id", "state", "state_name", "county_id", "county", "county_name", "zip_id", "zip_code", "zip", "zip_name", "address"},
 *      @SWG\Property(
 *          property="id",
 *          description="id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="title",
 *          description="title",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="cover",
 *          description="cover",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="item_id",
 *          description="item_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="channel_id",
 *          description="channel_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="read_num",
 *          description="read_num",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="state_id",
 *          description="state_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="state",
 *          description="state",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="state_name",
 *          description="state_name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="county_id",
 *          description="county_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="county",
 *          description="county",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="county_name",
 *          description="county_name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="zip_id",
 *          description="zip_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="zip_code",
 *          description="zip_code",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="zip",
 *          description="zip",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="zip_name",
 *          description="zip_name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="address",
 *          description="address",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="status",
 *          description="status",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="updated_at",
 *          description="updated_at",
 *          type="string",
 *          format="date-time"
 *      ),
 *      @SWG\Property(
 *          property="created_at",
 *          description="created_at",
 *          type="string",
 *          format="date-time"
 *      )
 * )
 */
class House extends Model
{
    use SoftDeletes;

    public $table = 'houses';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'title',
        'cover',
        'content',
        'price',
        'web_url',
        'item_id',
        'channel_id',
        'base_code',
        'country',
        'state_id',
        'state',
        'state_name',
        'county_id',
        'county',
        'county_name',
        'zip_id',
        'zip_code',
        'zip',
        'zip_name',
        'address'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'title' => 'string',
        'cover' => 'string',
        'price' => 'string',
        'web_url' => 'string',
        'item_id' => 'integer',
        'channel_id' => 'integer',
        'read_num' => 'integer',
        'base_code' => 'string',
        'state_id' => 'integer',
        'state' => 'string',
        'state_name' => 'string',
        'county_id' => 'integer',
        'county' => 'string',
        'county_name' => 'string',
        'zip_id' => 'integer',
        'zip_code' => 'string',
        'zip' => 'string',
        'zip_name' => 'string',
        'address' => 'string',
        'status' => 'integer'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'title' => 'required|between:1,50',
        'price' => 'nullable|numeric',
        'content' => 'required',
        'base_code' => 'required',
        'country' => 'required',
        'state_id' => 'required',
        'state' => 'required_unless:state_id,0',
        'state_name' => 'required_unless:state_id,0',
        'county_id' => 'required',
        'county' => 'required_unless:county_id,0',
        'county_name' => 'required_unless:county_id,0',
        'zip_id' => 'required',
        'zip_code' => 'required_unless:zip_id,0',
        'zip' => 'required_unless:zip_id,0',
        'zip_name' => 'required_unless:zip_id,0',
        'address' => 'required',
    ];

}